import os


def check_and_create_directory(path):
    if not os.path.exists(path):
        os.makedirs(path)
    else:
        pass


def list_all_files(directory, file_end = '.jpg'):
    '''
    List all files with file_end == '.jpg' in directory.
    '''
    dir = []
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith(file_end):
                file_path = os.path.join(root, file)
                dir.append(file_path)

    return sorted(dir) # 强制排序

def chunk_list(lst, chunk_size):
    """
    Split a list into chunks of a specified size.
    """
    return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]